package com.qdu.web.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qdu.common.annotation.Log;
import com.qdu.common.core.controller.BaseController;
import com.qdu.common.core.domain.AjaxResult;
import com.qdu.common.enums.BusinessType;
import com.qdu.bussiness.domain.BusCoach;
import com.qdu.bussiness.service.IBusCoachService;
import com.qdu.common.utils.poi.ExcelUtil;
import com.qdu.common.core.page.TableDataInfo;

/**
 * 教练信息Controller
 * 
 * @author qdu
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/bussiness/coach")
public class BusCoachController extends BaseController
{
    @Autowired
    private IBusCoachService busCoachService;

    /**
     * 查询教练信息列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCoach busCoach)
    {
        startPage();
        List<BusCoach> list = busCoachService.selectBusCoachList(busCoach);
        return getDataTable(list);
    }

    /**
     * 导出教练信息列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:export')")
    @Log(title = "教练信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusCoach busCoach)
    {
        List<BusCoach> list = busCoachService.selectBusCoachList(busCoach);
        ExcelUtil<BusCoach> util = new ExcelUtil<BusCoach>(BusCoach.class);
        util.exportExcel(response, list, "教练信息数据");
    }

    /**
     * 获取教练信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:query')")
    @GetMapping(value = "/{coachId}")
    public AjaxResult getInfo(@PathVariable("coachId") Long coachId)
    {
        return AjaxResult.success(busCoachService.selectBusCoachByCoachId(coachId));
    }

    /**
     * 新增教练信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:add')")
    @Log(title = "教练信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCoach busCoach)
    {
        return toAjax(busCoachService.insertBusCoach(busCoach));
    }

    /**
     * 修改教练信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:edit')")
    @Log(title = "教练信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCoach busCoach)
    {
        return toAjax(busCoachService.updateBusCoach(busCoach));
    }

    /**
     * 删除教练信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:coach:remove')")
    @Log(title = "教练信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coachIds}")
    public AjaxResult remove(@PathVariable Long[] coachIds)
    {
        return toAjax(busCoachService.deleteBusCoachByCoachIds(coachIds));
    }
}
